package com.java.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.java.entity.Rrc;
import com.java.utils.JDBCUtils;

public class RrcDao {
	
	
	
	public int insert(Rrc rrc) {
		String sql = "insert into rrc(registertime,number,risk) values(?,?,?)";
		List<Object> params = new ArrayList<>();
		params.add(rrc.getRegistertime());
		params.add(rrc.getNumber());
		params.add(rrc.getRisk());		
		return JDBCUtils.excuteUpdate(sql, params);
	}
	
	public List<Rrc> queryAll(){
		String sql ="select * from rrc";
		ResultSet rs = JDBCUtils.excuteQuery(sql, null);
		List<Rrc> list = new ArrayList<>();
		try {
			while(rs.next()) {
				Rrc r = new Rrc();
				r.setRegion(rs.getInt("region"));
				r.setRegistertime(rs.getDate("registertime"));
				r.setNumber(rs.getInt("number"));
				r.setRisk(rs.getInt("risk"));
				list.add(r);
			}
			return list;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
}
